﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args) //
        {
            /* Console.WriteLine(CompareString2("bbb", "abb"));
             return;*/
            string[] ar = { "abc", "abm", "vb", "zz" /*, "ded", "d", "a", "z", "a", "ab", "d", "abcs", "ab" */};
            int alg = 0;
            for (int i = 1; i < ar.Length; i++)
            {
                for (int j = ar.Length - 1 - i; j < ar.Length - 1; j++)
                {
                    alg++;
                    int res = CompareString2(ar[j], ar[j + 1]);
                    if (res == 1)
                    {
                        string tmp = ar[j];
                        ar[j] = ar[j + 1];
                        ar[j + 1] = tmp;
                    }
                    else 
                    {
                        break;
                    }
                }
            }
            Console.WriteLine("hello: " + alg);
            foreach (var el in ar)
            {
                Console.WriteLine(el);
            }
            Console.WriteLine("array length: " + ar.Length + " complexity: " + alg);
        }


        static int CompareString2(string s1, string s2)
        {
            int res = -2;

            for (int i = 0; i < Math.Min(s1.Length, s2.Length); i++)
            {
                if (s1[i] < s2[i])
                {
                    return 2;
                }
                else if (s1[i] > s2[i])
                {
                    return 1;
                }
                /*else if (s1[i] == s2[i] && s1.Length == s2.Length)
                {
                    if (i == s1.Length - 1)
                    {
                        res = 0;
                        break;
                    }
                }*/
                /*else if (s1[i] == s2[i] && s2.Length < s1.Length)
                {
                    if (i == s2.Length - 1)
                    {
                        res = 1;
                        break;
                    }
                }
                else if (s1[i] == s2[i] && s2.Length > s1.Length)
                {
                    if (i == s1.Length - 1)
                    {
                        res = 2;
                        break;
                    }
                }*/
            }

            if (s1.Length > s2.Length)
            {
                return 1;
            }
            if (s2.Length > s1.Length)
            {
                return 2;
            }
            return 0;
        }
    }
}
